srvMap.add('queryAreaCityForUser', '','front/sh/sceneMonitor!execute?uid=queryAreaCityForUser');//地图上地市
srvMap.add('queryRegionTopByCity', '','front/sh/sceneMonitor!execute?uid=queryRegionTopByCity');//询景区按地市分组前N个
var map; // 百度地图实例
var DEPLOY_PROVINCE_NAME_SHORT = DEPLOY_PROVINCE_NAME_SHORT; //省份短名称

/*地图展示景区marker使用*/
var checkCityId;//页面地市ID
var blueIconUrl = "assets/css/images/blue_icon_01.png";
var yellowIconUrl = "assets/css/images/yellow_icon.gif";
var orangeIconUrl = "assets/css/images/orange_icon.gif";
var redIconUrl = "assets/css/images/red_icon.gif";
var greenIconUrl = "assets/css/images/green_icon.png";

var checkRegionType = "";	//景区等级 4A,5A
var checkCityName = "";		//页面地市名称
var checkSearchValue = "";	//景区搜索关键字

var centerPoint={}; //省市级地图中心点
var lastRegionId;

$(function() {
	$(document).ready(function(){
		// 初始化页面
		initPage();

		// 初始地图，不包含数据
		initMap();

		// 加载左侧景区监控数据
		//loadRegionMonitorData();

		//初始化地图景区撒点
		//loadRegionPoits(null,null,null);
		initRegionPoits();

		//初始化天气
		//initWeather();
		
		/** 绑定DOM事件方法**/
		//景区搜索
		$(".scenicSearch span").click(function() {
			var regionName = $(".regionNameInput").val();
			searchRegion(regionName);
		});

		//搜索框回车
		$(".regionNameInput").keydown(function(e) {
			if (e.keyCode == 13) {
				$(".scenicSearch span").trigger("click"); //处理事件
			}
		});
		
		//景区下拉列表
		$("#scenicOption").click(function(){
			var status = $(this).attr("status");
			if (status == "close") {
				$("#scenicOptionDown").show();
				$(this).attr("status","open");
			}else {
				$("#scenicOptionDown").hide();
				$(this).attr("status","close");
			}
		});
		$("#scenicOptionDownAll").click(scenicOptionClick);
		$("#scenicOptionDown5A").click(scenicOptionClick);
		$("#scenicOptionDown4A").click(scenicOptionClick);
		$("#scenicOptionDown3A").click(scenicOptionClick);
		
		//返回页面初始状态
		$("a.btnBack").click(function(){
			self.location.reload();
			return false;
		});
		
		
		//预警处理：取消
		$("#warnDealCancel").click(function (){
			$("#iMessage").hide();
		});
		
		//预警处理：提交
		$("#warnDealSubmit").click(function (){
			var checkPhoneFlag=true;
			var phones = "";
			var msgContent = "";
			msgContent = $("#msgContent").val().trim();
			if ( msgContent ==null || msgContent == "" ) {
				alert("请输入短信通知的内容！");
				return false;
			}
			$(".numberBox2 ul li input").each(function (){
				var flag = checkNameUnique($(this));
				if (!flag) {
					checkPhoneFlag=false;
				}
				var phone = $(this).val().trim();
				if (phone!=null) {
					phones+=phone+',';
				}
			});
			var phonelist = phones.split(",");
			if (!checkPhoneFlag) {
				alert("手机号码为空或格式错误！");
				return;
			}
			$("#iMessage").hide();
			//var url = CONTENT_PATH + "/com.asiainfo.zhly.SceneMonitorAction.infoDealByRegionId.invoke";;
			var url = "http://sms.gx12301.net:8081/api/yd/sms.jsp";
			for(var i=0;i<phonelist.length;i++){
				var data = {
						custId:"10035",
						apikey:"fc8c95bb31f93582fd1415a11dc33ade",
						phone:phonelist[i],
						content:msgContent
					};
				sendSms(url,data);
				sleep(600);
			}
			alert("短信发送成功");
		});
	});
});

function sleep(n) {
    var start = new Date().getTime();

    while(true)if(new Date().getTime()-start > n) break;

    }

function sendSms(url,data){
	$.ajax({
		url: url,
		type: "post",
		data:data,
		success: function(result) {
             //alert(result);
         }
		
	});
}
/**
 * 初始化页面
 * @return {[type]} [description]
 */
function initPage() {
	var wh = $("body").height();
	//高度设置
	$(".box,.leftBox,.rightBox").height(wh);
	$(".left_list,.map").height(wh - 42);
	$(".left_list ul").height(wh - 42);
	
	$(window).resize(function() {
		var wh = $("body").height();
		//高度设置
		$(".box,.leftBox,.rightBox").height(wh);
		$(".left_list,.map").height(wh - 42);
		$(".left_list ul").height(wh - 42);
	});
	//城市选择
	$(".cityDiv").click(function() {
		if (!$(this).hasClass("cityDivShow")) {
			$(".cityList").show();
			$(this).addClass("cityDivShow");

		} else {
			$(".cityList").hide();
			$(this).removeClass("cityDivShow")
		}
	});
	//左侧收缩
	//左侧收缩
	$(".leftBox .switch").click(function() {
		if (!$(this).hasClass("switchShow")) {
			$(".leftBox").animate({
				opacity: "show",
				marginLeft: "-260px"
			}, "1000", function() {
				$(".leftBox").css("margin-left", -260);
				$(".leftBox .switch").addClass("switchShow");
			});
			$(".rightBox").animate({
				marginLeft: "0"
			}, "normal", function() {
				$(".rightBox").css("margin-left", 0);
				
				//向左扩大map范围
				//map.panTo(new BMap.Point(centerPoint.lon,centerPoint.lat),{noAnimation : true});
				//map.centerAndZoom(new BMap.Point(centerPoint.lon,centerPoint.lat),8);
			});	
		} else {
			$(".leftBox").animate({
				opacity: "show",
				marginLeft: "0px"
			}, "1000", function() {
				$(".leftBox").css("margin-left", 0);
				$(".leftBox .switch").removeClass("switchShow");
			});
			$(".rightBox").animate({
				marginLeft: "230px"
			}, "normal", function() {
				$(".rightBox").css("margin-left", 260);
				
				//向右缩小map范围
				//map.panTo(new BMap.Point(centerPoint.lon,centerPoint.lat),{noAnimation : true});
			});	
		}
	});
	//左侧下钻
}

/**
 * 
 * @Description : 初始地图，不包含数据
 * @return void
 * 
 * @author : wucm
 * @date : 2015年6月30日 上午10:51:48
 * 
 */
function initMap() {
	if (typeof(BMap) == "undefined") {
		alert("网络延迟导致地图未正确加载，请手动刷新刷新页面重新加载");
		return;
	}

	if (!map) {
		
		centerPoint.lon = DEPLOY_PROVINCE_CORE_LNG;
		centerPoint.lat = DEPLOY_PROVINCE_CORE_LAT;
		
		map = new BMap.Map("map",{minZoom:MAP_MINZOOM,maxZoom:MAP_MAXZOOM});
		map.centerAndZoom(new BMap.Point(centerPoint.lon,centerPoint.lat), MAP_MINZOOM);
		map.disableDoubleClickZoom();
		map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放
		
		// 地图自定义，屏蔽铁路等信息
		map.setMapStyle({
			styleJson: [{
				"featureType": "railway",
				"elementType": "all",
				"stylers": {
					"visibility": "off"
				}
			}, {
				"featureType": "highway",
				"elementType": "geometry",
				"stylers": {
					"visibility": "off"
				}
			}, {
				"featureType": "highway",
				"elementType": "labels",
				"stylers": {
					"visibility": "off"
				}
			}, {
				"featureType": "label",
				"elementType": "all",
				"stylers": {
					"visibility": "off"
				}
			}, {
				"featureType": "poi",
				"elementType": "all",
				"stylers": {
					"visibility": "off",
					"color": "#ffffff"
				}
			}, {
				"featureType": "administrative",
				"elementType": "all",
				"stylers": {
					"visibility": "off",
					"color": "#ffffff"
				}
			}, {
				"featureType": "background",
				"elementType": "all",
				"stylers": {
					"color": "#F3F2EE"
				}
			}]
		});
		// 初始地图上各地市
		initMapCity();
		
		
		/*map.addEventListener("rightclick", function mapClick(e) {
			alert(e.point.lng + "," + e.point.lat);
		});*/
	}
};


/**
 * 
 * @Description : 初始化地图上各地市
 * @return void
 * 
 * @author : wucm
 * @date : 2015年7月20日 下午4:02:49
 * 
 */
function initMapCity() {


	Util.ajax.postJsonSync(srvMap.get('queryAreaCityForUser'),null,function(json,status){
		if(status){
			var citys = json.object.regions;
			var loadCityNum = 0;
			var coreLon = 0;
			var coreLat = 0;	//赋值给最后一个地市，暂时无法满足2个地市保持中心定位放大
			for (var i = 0; i < citys.length; i++) {
				if (citys[i].hasRight) {
					var c = citys[i];

					// 添加各地市名称的标签
					loadMapCityLabel(c);
					
					// 初始化市级区域边界
					initMapBoundary(c);
					
					// 初始化市级区域边界，对监控区域特殊处理
					initMapBoundaryWarn(c);
					
					loadCityNum++;
					
					coreLon = c.coreLongitude;
					coreLat = c.coreLatitude;
				}
			}
			
			//判断加载地市个数，从而放大地图层级
			if( loadCityNum <= 2 ){
				map.centerAndZoom(new BMap.Point(coreLon, coreLat), MAP_MINZOOM);
				map.setMinZoom(MAP_MINZOOM);
				map.setMaxZoom(MAP_MAXZOOM);
				
				centerPoint.lon = coreLon;
				centerPoint.lat = coreLat;
				
				$("#areaNameTitle1").html(c.areaName);
				$("#areaNameTitle2").html("全省->"+c.areaName);
				
				initWeather(c.areaName);
			}else{
				initWeather("");
			}
		}else{
			 alert('错误','数据异常！');   
		}
	});
	// var url = CONTENT_PATH + "/com.asiainfo.zhly.CommonAction.queryCityForMain.invoke";
	// Base.ajax({
	// 	url: url,
	// 	async: false,
	// 	success: function(req) {
	// 		if (null == req || null == req.result) {
	// 			return;
	// 		}

	// 		var citys = req.result;
	// 		var loadCityNum = 0;
	// 		var coreLon = 0;
	// 		var coreLat = 0;	//赋值给最后一个地市，暂时无法满足2个地市保持中心定位放大
	// 		for (var i = 0; i < citys.length; i++) {
	// 			if (citys[i].hasRight) {
	// 				var c = citys[i];

	// 				// 添加各地市名称的标签
	// 				loadMapCityLabel(c);
					
	// 				// 初始化市级区域边界
	// 				initMapBoundary(c);
					
	// 				// 初始化市级区域边界，对监控区域特殊处理
	// 				initMapBoundaryWarn(c);
					
	// 				loadCityNum++;
					
	// 				coreLon = c.coreLongitude;
	// 				coreLat = c.coreLatitude;
	// 			}
	// 		}
			
	// 		//判断加载地市个数，从而放大地图层级
	// 		if( loadCityNum <= 2 ){
	// 			map.centerAndZoom(new BMap.Point(coreLon, coreLat), 9);
	// 			map.setMinZoom(9);
	// 			map.setMaxZoom(13);
				
	// 			centerPoint.lon = coreLon;
	// 			centerPoint.lat = coreLat;
				
	// 			$("#areaNameTitle1").html(c.areaName);
	// 			$("#areaNameTitle2").html("全省->"+c.areaName);
				
	// 			initWeather(c.areaName);
	// 		}else{
	// 			initWeather("");
	// 		}
	// 	}
	// });
}


/**
 * 
 * @Description : 初始化市级区域边界
 * @return void
 * 
 * @author : wucm
 * @date : 2015年5月29日 下午1:40:32
 * 
 */
function initMapBoundary(city) {
	var areaId = city.areaId;
	var areaName = city.areaName;
	var coreLongitude = city.coreLongitude;
	var coreLatitude = city.coreLatitude;

	var hasRight = city.hasRight;
	if (hasRight) {
		return;
	}
	var bdary = new BMap.Boundary();
	bdary.get(areaName, function(rs) { // 获取行政区域
		var ply = new BMap.Polygon(rs.boundaries[0], {
			strokeWeight: 2,
			strokeColor: "#6495ed",
			fillOpacity: 0.3,
			fillColor: "#f4f3ef"
		}); // 建立多边形覆盖物
		map.addOverlay(ply); // 添加覆盖物
	});
};


/**
 * 
 * @Description : 初始化市级区域边界，对监控区域特殊处理
 * @return void
 * 
 * @author : wucm
 * @date : 2015年6月30日 上午11:09:47
 * 
 */
function initMapBoundaryWarn(city){
	var areaId = city.areaId;
	var areaName = city.areaName;
	var coreLongitude = city.coreLongitude;
	var coreLatitude = city.coreLatitude;
	var hasRight = city.hasRight;
	
	if (null == coreLongitude || null == coreLatitude || !hasRight) {
		return;
	}

	var bdary = new BMap.Boundary();
	bdary.get(areaName, function(rs) { // 获取行政区域
		var ply = new BMap.Polygon(rs.boundaries[0], {
			strokeWeight: 2,
			strokeColor: "#6495ed",
			fillOpacity: 0.3,
			fillColor: "#4ecaee"
		}); // 建立多边形覆盖物
		ply.areaId = areaId;
		
		map.addOverlay(ply); // 添加覆盖物
		ply.addEventListener("mouseover", function() {
			ply.setFillColor("#cdbc43");
			ply.setFillOpacity("0.3");
		});
		ply.addEventListener("mouseout", function() {
			ply.setFillColor("#4ecaee");
			ply.setFillOpacity("0.3");
		});
		ply.addEventListener("click", function() {
//			alert(areaId+areaName);
			checkCityId = areaId;
			checkCityName = areaName;
			
			
			gotoCityMap(city);
			initWeather(areaName);
			
			$("#areaNameTitle1").html(areaName);
			$("#areaNameTitle2").html("全省->"+areaName);
		});
		
	});
};


/**
 * 
 * @Description : 进入市级地图
 * @return void
 * 
 * @author : pengjy
 * @date : 2015年11月11日 上午11:11:11
 * 
 */
function gotoCityMap(city){
	var areaId = city.areaId;
	var areaName = city.areaName;
	var coreLongitude = city.coreLongitude;
	var coreLatitude = city.coreLatitude;
	
	checkCityId = areaId;
	
	//遍历地市，隐藏其它地市和标识
	var overlays = map.getOverlays();
	for(var i=0; i<overlays.length; i++){
		if( overlays[i].areaId && overlays[i].areaId == areaId ){
			
		}else{
			map.removeOverlay(overlays[i]);
		}
	}
	
	map.centerAndZoom(new BMap.Point(coreLongitude, coreLatitude), MAP_MINZOOM);
	map.setMinZoom(MAP_MINZOOM);
	map.setMaxZoom(MAP_MAXZOOM);
	
	centerPoint.lon = coreLongitude;
	centerPoint.lat = coreLatitude;
	
	
	loadRegionPoits(checkCityId, null, null, 10000);
	
	//还原景区类型选项
	$("#scenicOptionDown").hide();
	$("#scenicOption").html($("#scenicOptionDownAll").html());
	$("#scenicOption").attr("status","close");
	checkRegionType = "";
	
	//还原左侧列表搜索框
	$(".regionNameInput").val("搜索景区，请输入名称");
	checkSearchValue = "";
}

/**
 * 
 * @Description : 添加各地市名称的标签
 * @return void
 * 
 * @author : wucm
 * @date : 2015年5月29日 下午1:41:26
 * 
 */
function loadMapCityLabel(city) {
	var areaId = city.areaId;
	var areaName = city.areaName;
	var coreLongitude = city.coreLongitude;
	var coreLatitude = city.coreLatitude;
	var hasRight = city.hasRight;

	if (!hasRight) {
		return;
	}

	var opts = {
		position: new BMap.Point(coreLongitude, coreLatitude), // 指定文本标注所在的地理位置
		offset: new BMap.Size(-10, -25)
			// 设置文本偏移量
	}
	var label = new BMap.Label(areaName, opts); // 创建文本标注对象
	label.setStyle({
		color: "#000000",
		fontSize: "14px",
		height: "20px",
		lineHeight: "20px",
		fontFamily: "微软雅黑",
		border:0,
		//borderColor: '#f4f3ef',
		backgroundColor: null,
		//padding: "3px 5px",
		opacity: 0.7
	});
	label.areaId = areaId;
	map.addOverlay(label);
	label.setStyle({
		cursor: "pointer"
	});
};



/**
 * 
 * @Description : 初始化景区撒点，默认地市2个景点
 * @return void
 * 
 * @author : pengjy
 * @date : 2015年11月4日 上午11:09:47
 * 
 */
function initRegionPoits(){

	//初始化左侧景区列表
	var par = "&topNum="+10000;
	Util.ajax.postJsonSync(srvMap.get('queryRegionTopByCity'),par,function(json,status){
		if(status){
			loadRegionMonitorData(json.object.data);
		}else{
			 alert('错误','数据异常！');   
		}
	});
	
	Util.ajax.postJsonSync(srvMap.get('queryRegionTopByCity'),null,function(json,status){
		if(status){
			buildRegionPoits(json.object.data);
		}else{
			 alert('错误','数据异常！');   
		}
	});
}


/**
 * 
 * @Description : 加载景区撒点
 * @return void
 * 
 * @author : pengjy
 * @date : 2015年11月1日 上午11:09:47
 * 
 */
function loadRegionPoits( cityId,regionType,searchValue,topNum ){
	if (cityId == null||typeof(cityId) == 'undefined') {
		cityId='';
	}
	if (regionType == null||typeof(regionType) == 'undefined') {
		regionType='';
	}
	if (searchValue == null||typeof(searchValue) == 'undefined') {
		searchValue='';
	}
	if (topNum == null||typeof(topNum) == 'undefined') {
		topNum='';
	}
	var par = "&cityId="+cityId+"&regionType="+regionType+"&searchValue="+searchValue+"&topNum="+topNum;
	Util.ajax.postJsonSync(srvMap.get('queryRegionTopByCity'),par,function(json,status){
		if(status){
			buildRegionPoits(json.object.data);
			loadRegionMonitorData(json.object.data);
		}else{
			 alert('错误','数据异常！');   
		}
	});
}

/**
 * 
 * @Description : 创建景区撒点
 * @return void
 * 
 * @author : pengjy
 * @date : 2015年11月1日 上午11:09:47
 * 
 */
function buildRegionPoits(data){
	//清除地图上所有原有景点信息
	var overlays = map.getOverlays();
	for(var i=0; i<overlays.length; i++){
		if( overlays[i] instanceof BMap.Marker ){
			map.removeOverlay(overlays[i]);
		}
	}
	
	//打上新的景点信息
	for (var i = 0; i < data.length; i++) {
		var areaId = data[i].areaId;
		var areaName = data[i].areaName;
		var warnLevelId = data[i].warnLevelId;
		var stayPersonCnts = data[i].stayPersonCnts;
		var sumVstCnts = data[i].sumVstCnts;
		var lat = data[i].lat;
		var lng = data[i].lng;
		var point = new BMap.Point(lng, lat);
		
		// 展示区域的marker
		var blueIcon = new BMap.Icon(greenIconUrl,
			new BMap.Size(30, 50));
		var marker = new BMap.Marker(point, {
			icon: blueIcon
		});
		
		//根据预警判断景点标识颜色
		if (warnLevelId == "1") {
			var yellowIcon = new BMap.Icon(yellowIconUrl,new BMap.Size(30, 50));
			marker.setIcon(yellowIcon);
		}else if (warnLevelId == "2") {
			var orangeIcon = new BMap.Icon(orangeIconUrl,new BMap.Size(30, 50));
			marker.setIcon(orangeIcon);
		}else if (warnLevelId == "3") {
			var redIcon = new BMap.Icon(redIconUrl,new BMap.Size(30, 50));
			marker.setIcon(redIcon);
		}
		
		marker.setTop(true);
		marker.regionId = data[i].areaId;
		marker.region = data[i];
		map.addOverlay(marker);
		
		//设置景点鼠标悬浮事件
		marker.addEventListener("mouseover", function(e){
			//加载景点展示信息
			loadRegionMouseOverData(this);
			
			//高亮左侧列表对应数据--悬浮已有信息
		});
		marker.addEventListener("mouseout", function(e){
			map.closeInfoWindow();
			
			
		});
		
		//点击景点进行下钻
		marker.addEventListener("click", function(e){
			var _regionId = this.regionId.EncodeBase64();
			location.href=CONTENT_PATH+"/zhly/scene_monitor_sub.jsp?regionId="+_regionId;
		});
		
	}
}


/**
 * 
 * @Description : 展示景点鼠标悬浮数据
 * @return void
 * 
 * @author : xuxiong
 * @date : 2015年11月10日
 * 
 */
function loadRegionMouseOverData(marker){
	
	if(!marker){return false;}
	
	//修改图片样式
	var regionObj = $("#"+marker.region.areaId);
	var level = regionObj.attr("level");
		
	var classType="";
	if(level == 5){
		classType = "photoS5";
	}else if(level == 4){
		classType = "photoS4";
	}else if(level == 3){
		classType = "photoS3";
	}else if(level == 2){
		classType = "photoS2";
	}else if(level == 1){
		classType = "photoS1";
	}else{
		classType = "photoS0";
	}
	
	$("#regionImage").attr("class","");
	$("#regionImage").addClass(classType);
	
	//修改展示名称
	$(".warnning_tanchuang .li1S").text(marker.region.areaName);
	
	var stayPersonCnts = marker.region.stayPersonCnts || 0;
	var sumVstCnts = marker.region.sumVstCnts || 0;
	
	$("#regionStayCnts").text(stayPersonCnts);
	$("#regionSumCnts").text(sumVstCnts);
	
	var opts = {
			width: 400, // 信息窗口宽度
			enableMessage: false
		};
	var infoWindow = new BMap.InfoWindow($("#warnning_tanchuang").html(), opts);
	infoWindow.addEventListener("open", function(e) {
		// 移除关闭图标
		$.each($(".BMap_pop").find("img"), function() {
			$(this).remove();
		});

		// 移除百度信息框自带的外边框
		$(".BMap_pop").find(".BMap_top").removeClass("BMap_top");
		$(".BMap_pop").find(".BMap_center").removeClass("BMap_center");
		$(".BMap_pop").find(".BMap_bottom").removeClass("BMap_bottom");

		$($(".BMap_pop").children("div")[0]).empty();
		$($(".BMap_pop").children("div")[2]).empty();
		$($(".BMap_pop").children("div")[4]).empty();
		$($(".BMap_pop").children("div")[6]).empty();
	});
	map.openInfoWindow(infoWindow,marker.getPosition());
}

/**
 * 
 * @Description : 初始化天气
 * @return void
 * 
 * @author : pengjy
 * @date : 2015年11月11日 上午11:09:47
 * 
 */
function initWeather(cityName){
	if (cityName == null || cityName == "全省" || cityName =="") {
		 cityName = DEPLOY_PROVINCE_CAPITAL_NAME; //展示天气的地市
	}
	BWeather.weather(cityName, function callback(data) {
		var mainWeatherCity = data.results[0].currentCity;
		var mainWeather = data.results[0].weather_data[0].weather; //天气：多云..等
		var mainTemperature = data.results[0].weather_data[0].date.substring(14, 17); //气温：5℃
		//var icon = data.results[0].weather_data[0].dayPictureUrl;
		var pm25 = data.results[0].pm25;
		$("#mainWeatherCity").html(mainWeatherCity);
		$("#mainWeather").html(mainWeather);
		$("#mainTemperature").html(mainTemperature);
		$("#weatherIcon").css("width:auto", null);
		//$("#weatherIcon").css("background", "url(" + icon + ") no-repeat center center");
		//处理天气面板
		var wBoxULHtml="";
		var weatherData = data.results[0].weather_data;
		var todayH1="";
		for (var i = 0; i < weatherData.length; i++) {
			var tStr ="";
			if (i == 0) {
				var h1=weatherData[0].date;
				todayH1 = "<span>$h1</span>";
				todayH1=todayH1.replace(/\$h1/g,h1);
				var temperature = weatherData[i].temperature;
				var weather = weatherData[i].weather;
				var wind = weatherData[i].wind
				var weatherPic=getWeatherPic(weather);

				$("#weatherIcon").css("background", "url(" + weatherPic + ") no-repeat center center");
				$("#weatherIcon").css("background-size", "70%");
				$("#weatherIcon").css("background-color", "#C8D6FD");
				
				tStr="<li ><div class=\"today_weather\"><div class=\"big_icon_weather\">" +
				//assets/css/images/weather/TB_yin.png
						"<img src=\"$wPic\" width=\"70\" height=\"70\"  alt=\"\"/></div>" +
						"<h2>$temperature</h2><h3>$weather</h3>" +
						"<p>$wind</p><p>空气质量：<i style=\"background-color:$color\">$pm25</i></p></div></li>";
				tStr = tStr.replace(/\$temperature/g,temperature);
				tStr = tStr.replace(/\$weather/g,weather);
				tStr = tStr.replace(/\$wind/g,wind);
				tStr = tStr.replace(/\$wPic/g,weatherPic);
				if (pm25<=50) {
					tStr = tStr.replace(/\$pm25/g,pm25+"优");
					tStr = tStr.replace(/\$color/g,"#6EB720");
				}else if (pm25>50 && pm25<=100) {
					tStr = tStr.replace(/\$pm25/g,pm25+"良");
					tStr = tStr.replace(/\$color/g,"#D6C60F");
				}else if (pm25>100 && pm25<= 150) {
					tStr = tStr.replace(/\$pm25/g,pm25+"轻度污染");
					tStr = tStr.replace(/\$color/g,"#EC7E22");
				}else if (pm25>150 && pm25<=200) {
					tStr = tStr.replace(/\$pm25/g,pm25+"中度污染");
					tStr = tStr.replace(/\$color/g,"E92D00");
				}else if (pm25>200) {
					tStr = tStr.replace(/\$pm25/g,pm25+"重度污染");
					tStr = tStr.replace(/\$color/g,"#B414BB");
				}
			}else {
				var week = weatherData[i].date;
				var date = getDateByNum(i);
				var temperature = weatherData[i].temperature;
				var weather = weatherData[i].weather;
				var wind = weatherData[i].wind;
				var weatherPic=getWeatherPic(weather);
				tStr = " <li ><div class=\"next_weather\">" +
				"<p>$week</p><p class=\"pgreycolor\">$date</p><div class=\"min_icon_weather\"> " +
				//assets/css/images/weather/TB_yin_min.png
				"<img src=\"$wPic\" width=\"45\" height=\"45\"  alt=\"\"/></div>" +
				"<p>$temperature</p><p>$weather</p><p>$wind</p></div></li>"
				tStr = tStr.replace(/\$week/g,week);
				tStr = tStr.replace(/\$date/g,date);
				tStr = tStr.replace(/\$temperature/g,temperature);
				tStr = tStr.replace(/\$weather/g,weather);
				tStr = tStr.replace(/\$wind/g,wind);
				tStr = tStr.replace(/\$wPic/g,weatherPic);
			}
			wBoxULHtml+=tStr;
		}
		$("#weatherBoxH1").html(todayH1);
		$("#weatherBoxUL").html(wBoxULHtml);
	});
}


/**
 * 
 * @Description : 景区列表点击事件
 * @return void
 * 
 * @author : pengjy
 * @date : 2015年11月11日 上午11:09:47
 * 
 */
function scenicOptionClick(){
	checkRegionType = $(this).attr("regionType");
	$("#scenicOptionDown").hide();
	$("#scenicOption").html($(this).html());
	$("#scenicOption").attr("status","close");
	
	//过滤左侧景区列表
	loadRegionPoits(checkCityId,checkRegionType,checkSearchValue,10000);
}


/**
 * 
 * @Description : 搜索景区
 * @param : regionName 景区名称关键字
 * @return void
 * 
 * @author : xuxiong
 * @date : 2015年11月10日
 * 
 */
function searchRegion(regionName) {
	
	if (regionName == null || regionName.length == 0 || regionName=="搜索景区，请输入名称") { //查询条件为空，展示全部
		checkSearchValue = "";
	}else{
		checkSearchValue = regionName;
	}
	
	loadRegionPoits(checkCityId,checkRegionType,checkSearchValue,10000);
	return false;
};


/**
 * 
 * @Description : 加载景区监控数据
 * @return void
 * 
 * @author : xuxiong
 * @date : 2015年11月10日
 * 
 */
function loadRegionMonitorData( data ) {
	var info=data;
	var content = "";
	if( data == null || data.length== 0 ){
		content = "<p align='center' style='color:red;'>没有相关数据！</p>";
		$("#regionList").html(content);
		$(".tcdPageCode").hide();
		return false;
	}
	
	//渲染到左侧列表中
	//getPageInfo();
	var strFormat = '<div class="scenicList regionRecord" id="$1" level="$5"><p class="pcs$2"></p><p id="n$1" class="pc2">$3</p><p class="p4"></p>'
		+'<p class="pc3" style="float:right;margin-right:10px;"><span>$4</span> 人</p></div>';
	
	for (var i = 0; i < data.length; i++) {
		
		var areaId = data[i].areaId;
		var areaName = data[i].areaName;
		var warnLevelId = data[i].warnLevelId;
		var stayPersonCnts = data[i].stayPersonCnts || 0;
		var regionType = data[i].regionType;
		
		content += strFormat.replace(/\$1/g, areaId)
			.replace("$2", warnLevelId)
			.replace("$3", areaName)
			.replace("$4", stayPersonCnts)
			.replace("$5", regionType);
	}
	
	$("#regionList").empty().html(content);
	
	//设置滚动
	if( $("#regionList").children().length > 9 ){
		$("#regionList").textSlider();
	}
	//左侧景区列表点击事件--跳转到子监控页面
	$(".regionRecord").click(function() {
		var regionId = $(this).attr("id");
		var _regionId = regionId.EncodeBase64();
		location.href=CONTENT_PATH+"/zhly/scene_monitor_sub.jsp?regionId="+_regionId;
		return false;
	});
	
	//在地图上展示景点信息
	$(".regionRecord .pc2").mouseover(function() {
		$(this).removeClass("regionNameNormal");
		$(this).addClass("regionNameBold");
		
		var regionId = $(this).parent().attr("id");
		var dstRegionMarker;
		var overlays = map.getOverlays();
		for(var i=0; i<overlays.length; i++){
			if( overlays[i] instanceof BMap.Marker && overlays[i].regionId == regionId){
				dstRegionMarker = overlays[i];
				break;
			}
		}
		
		//加载景点展示信息
		loadRegionMouseOverData(dstRegionMarker);
		
		return true;
	});
	
	//取消列表中景区名称对应的事件
	$(".regionRecord .pc2").mouseout(function() {
		$(this).removeClass("regionNameBold");
		$(this).addClass("regionNameNormal");
		map.closeInfoWindow();
		return true;
	});
	
	//绑定发送通知信息
	$(".regionRecord .p4").click(function() {
		var regionId = $(this).parent().attr("id");
		var regionName = document.getElementById('n'+regionId).innerHTML
		$("#sceneName").empty().append(regionName);
		sendInfoSMS(regionId);
		return false;
	});
};


/**
 * 
 * @Description : 发送景区通知信息
 * @return void
 * 
 * @author : xuxiong
 * @date : 2015年12月27日
 * 
 */
function sendInfoSMS(regionId){
	//重置界面
	$("#phoneNums>li input").val("");
	$("#phoneNums>li:gt(0)").remove();
	$("#msgContent").val("");
	
	//展示界面
	$("#iMessage").show();
	
	//记录当前景区id
	lastRegionId = regionId;
}

/**
 * 校验电话输入框
 * @returns {String}
 */
function checkNameUnique(obj){
	var inputStr = $(obj).val().trim();
	var reg = /^0?1[3|4|5|8][0-9]\d{8}$/;
	if (inputStr!=null&&reg.test(inputStr)) {
		$(obj).css("border","1px solid #f2f2f2");
		return true;
	}else{
		$(obj).css("border","1px dotted red");
		return false;
	}
}


/**
 * 添加号码按钮增加事件
 */
function addPhoneOnclick(obj){
	var parentNode = obj.parentNode;
	parentNode.removeChild(obj);
	var li = document.createElement('li');
	var rand = Math.random();
	li.innerHTML = "<input id=\"phoneId_"+rand+"\"  onblur=\"checkNameUnique(this)\"  maxlength=\"11\" placeholder=\"请输入号码\" type=\"text\"><span id=\"phoneDelId_"+rand+"\" onclick=\"delPhoneOnclick(this)\">-</span>";
	spanHtml="<span id=\"addPhone\" onclick=\"addPhoneOnclick(this)\">+</span>";
	parentNode.appendChild(li);
	$("#phoneNums").append(spanHtml);
};

/**
 * 添加号码按钮删除事件
 */
function delPhoneOnclick(obj){
	var length = $("#phoneNums li").length;
	if (length<=1) {
		return;
	}
	var parentNode = obj.parentNode.parentNode;
	var phoneId = $(obj).attr("id").replace("phoneDelId","phoneId");
	var delObj = document.getElementById(phoneId);
	parentNode.removeChild(obj.parentNode);
};

/**
 * 生成日期
 * @param num
 * @returns
 */
function getDateByNum(num){
	var dd = new Date();
	dd.setDate(dd.getDate()+num);//获取AddDayCount天后的日期 
	var m = dd.getMonth()+1;//获取当前月份的日期 
	var d = dd.getDate(); 
	if(m<10){m="0"+m;}
	if(d<10){d="0"+d;}
	return m+"月"+d+"日"; 
}

/**
 * 生成天气PIC路径
 * @param num
 * @returns
 */
function getWeatherPic(weather,flag){
	var url="";
	//assets/css/images/weather/TB_yin.png
	if (weather.indexOf("雨夹雪")>-1) {
		url="assets/css/images/weather/sleet.png";
	}else if (weather.indexOf("暴雪")>-1) {
		url="assets/css/images/weather/snow_biggest.png";
	}else if (weather.indexOf("大雪")>-1) {
		url="assets/css/images/weather/snow_big.png";
	}else if (weather.indexOf("中雪")>-1) {
		url="assets/css/images/weather/snow_mid.png";
	}else if (weather.indexOf("小雪")>-1) {
		url="assets/css/images/weather/snow_small.png";
	}else if (weather.indexOf("暴雨")>-1) {
		url="assets/css/images/weather/rain_biggest.png";
	}else if (weather.indexOf("大雨")>-1) {
		url="assets/css/images/weather/rain_big.png";
	}else if (weather.indexOf("中雨")>-1) {
		url="assets/css/images/weather/rain_mid.png";
	}else if (weather.indexOf("小雨")>-1) {
		url="assets/css/images/weather/rain_small.png";
	}else if (weather.indexOf("雷阵雨")>-1) {
		url="assets/css/images/weather/thunder_shower .png";
	}else if (weather.indexOf("雷")>-1) {
		url="assets/css/images/weather/thunder .png";
	}else if (weather.indexOf("雨")>-1) {
		url="assets/css/images/weather/rain_small.png";
	}else if (weather.indexOf("阴")>-1) {
		url="assets/css/images/weather/overcast.png";
	}else if (weather.indexOf("雾")>-1) {
		url="assets/css/images/weather/fog.png";
	}else if (weather.indexOf("多云")>-1) {
		url="assets/css/images/weather/cloudy_sun.png";
	}else if (weather.indexOf("晴")>-1) {
		url="assets/css/images/weather/sunny_sun.png";
	}else if (weather.indexOf("扬")>-1) {
		url="assets/css/images/weather/sand_blowing .png";
	}else {
		url="assets/css/images/weather/default.png";
	}
	return url;
}